#include <string>

using std::string;

class Solution {
public:
    bool isPalindrome(string s) {
        int gap = 'a' - 'A';
        for (int i = 0; i < s.size(); i++) {
            if (s[i] >= 'A' && s[i] <= 'Z') {
                s[i] += gap;
            }
        }
        int i = 0, j = s.size() - 1;
        while (i < j) {
            while (i < j && !isTarget(s[i])) {
                i++;
            }
            while (i < j && !isTarget(s[j])) {
                j--;
            }
            if (s[i] == s[j]) {
                i++;
                j--;
            }
            else {
                return false;
            }
        }
        return true;
    }

    bool isTarget(int c) {
        return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
    }
};